//-----------------------------------------------------------------------
// <copyright file="Remove.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <author>Andy Reeves</author>
// <email>andyr</email>
// <date>2004-03-23</date>
// <summary>Removes performance counters from the local machine</summary>
//-----------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks.PerformanceCounters
{
    using System;
    using System.Xml;
    using System.Globalization;
    using System.Diagnostics;
    using Microsoft.Build.Framework;

    /// <summary>
    /// Removes performance counters from the local machine
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[<PerformanceCounters.Remove CategoryName="categoryName" />]]></code>
    /// <para>where:</para>
    /// <para><i>categoryName (Required)</i></para>
    /// <para>
    /// The name of the custom performance counter category to remove from the local computer. The specified 
    /// category and its associated counters will be removed.
    /// </para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test">
    ///         <PerformanceCounters.Remove
    ///             CategoryName="myCategory" />
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>
    public class Remove : TaskBase
    {
        private string categoryName = String.Empty;

        /// <summary>
        /// Initializes a new instance of the Remove class.
        /// </summary>
        public Remove()
        {
        }

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            #region Execute code
            Log.LogMessageFromResources("PerfCounter.RemoveCategory", categoryName);

            // Remove the category if it exists
            if (PerformanceCounterCategory.Exists(categoryName))
            {
                PerformanceCounterCategory.Delete(categoryName);
            }
            else
            {
                Log.LogMessageFromResources("PerfCounter.CategoryNotFound", categoryName);
            }
            #endregion
        }

        /// <summary>
        /// The name of the custom performance counter category to remove from the local computer.
        /// </summary>
        /// <value>The name of the custom performance counter category to remove from the local computer.</value>
        [Required]
        public string CategoryName
        {
            get
            {
                return (this.categoryName == null ? String.Empty : this.categoryName);
            }
            set
            {
                this.categoryName = value;
            }
        }
    }
}
